def sayhi():  # 函数名
    print("Hello, I'm nobody!")


sayhi()  # 调⽤函数


def calc(x, y):
    res = x ** y
    print(res)  # 函数执⾏结果


calc(5, 22)


def stu_register(name, age, country, course):
    print("----注册学⽣信息------")
    print("姓名:", name)
    print("age:", age)
    print("国籍:", country)
    print("课程:", course)


stu_register("王⼭炮", 22, "CN", "python_devops")
stu_register("张叫春", 21, "CN", "linux")
stu_register("刘⽼根", 25, "CN", "linux")


def stu_register(name, age, course='PY', country='CN'):
    print("----注册学⽣信息------")
    print("姓名:", name)
    print("age:", age)
    print("国籍:", country)
    print("课程:", course)


stu_register("王⼭炮", course='PY', age=22, country='JP')


def stu_register(name, age, *args):  # *args 会把多传⼊的参数变成⼀个元组形式
    print(name, age, args)


stu_register("Alex", 22)
# 输出
# Alex 22 () #后⾯这个()就是args,只是因为没传值,所以为空
stu_register("Jack", 32, "CN", "Python")


# 输出
# Jack 32 ('CN', 'Python')

def stu_register(name, age, *args, **kwargs):  # *kwargs 会把多传⼊的参数变成⼀个dict形式
    print(name, age, args, kwargs)


stu_register("Alex", 22)
# 输出
# Alex 22 () {}#后⾯这个{}就是kwargs,只是因为没传值,所以为空
stu_register("Jack", 32, "CN", "Python", sex="Male", province="ShanDong")


# 输出
# Jack 32 ('CN', 'Python') {'province': 'ShanDong', 'sex': 'Male'}

def print_info(*args, **kwargs):
    city = kwargs.pop("city", "大保健山")
    print("----info------")
    print("Name:", kwargs.get("name", "Unknown"))
    print("Age:", kwargs.get("age"))
    print("Sex:", kwargs.get("sex"))
    print("City:", city)


print_info(name="Alex", age=22, sex="M")
print_info(name="Jack", age=26, sex="M", city="ShangHai")


def stu_register(name, age, course='PY', country='CN'):
    print("----注册学⽣信息------")
    print("姓名:", name)
    print("age:", age)
    print("国籍:", country)
    print("课程:", course)
    if age > 22:
        return False
    else:
        return True


stu_register_status = stu_register("王⼭炮", 22, course="PY全栈开发", country='JP')
if stu_register_status:
    print("注册成功")
else:
    print("too old to be a student.")

name = "Alex Li"


def change_name():
    name = "⾦⻆⼤王, ⼀个有Tesla的⾼级屌丝"
    print("after change", name)


change_name()
print("在外⾯看看name改了么?", name)

name = "Alex Li"


def change_name():
    global name  # 声明⼀个全局变量
    name = "Alex ⼜名⾦⻆⼤王,爱⽣活、爱⾃由、爱姑娘"
    print("after change", name)


change_name()
print("在外⾯看看name改了么?", name)

d = {"name": "Alex", "age": 26, "hobbie": "⼤保健"}
l = ["Rebeeca", "Katrina", "Rachel"]


def change_data(info, girls):
    info["hobbie"] = "学习"
    girls.append("XiaoYun")


change_data(d, l)
print(d, l)
